<?php

namespace App\Library\ArrayTools;


class ArrayTools
{
    /**
     * 多维数组对键名进行重新排序
     * @param $by_ref_array
     * @author luwei
     * @date 2019-01-05 10:56
     */
    public static function recursive_key_sort(&$by_ref_array)
    {
        ksort($by_ref_array);
        foreach ($by_ref_array as $key => $value) {
            if (is_array($value))
            {
                self::recursive_key_sort($by_ref_array[$key]);
            }
        }
    }

    /**
     * Description: 二维数组key value互换
     * Author: Gxs
     * @param $data
     * @param $column
     * @return array
     */
    public static function valueToKey($data, $column)
    {
        $result = [];
        if (!empty($data)) {
            foreach ($data as $key=>$value) {
                if (isset($value[$column])) {
                    $result[$value[$column]] = $value;
                }
            }
        }
        return $result;
    }

    /**
     * Description: key值集合
     * Author: Gxs
     * @param $data
     * @param $column
     * @return array
     */
    public static function valuesToKey($data, $column)
    {
        $result = [];
        if (!empty($data)) {
            foreach ($data as $key=>$value) {
                if (isset($value[$column])) {
                    $result[$value[$column]][] = $value;
                }
            }
        }
        return $result;
    }
}